package com.xnfh.login.viewmodel

import com.xnfh.framework.base.BaseViewModel
import com.xnfh.framework.bean.RespStateData
import com.xnfh.framework.bean.UserInforBean
import org.json.JSONObject

/**
 * @Description:
 * @Author: ziheng
 * @CreateDate: 2024/1/3 16:26
 * @UpdateUser: ziheng
 * @UpdateDate: 2024/1/3 16:26
 * @UpdateRemark: 更新说明
 */
class LoginViewModel: BaseViewModel() {
    private val viewModelRes = LoginViewModelRes()
    val sendCodeBean = RespStateData<String>()
    val checkSmsCodeBean = RespStateData<String>()
    val loginBean = RespStateData<UserInforBean>()


    /**
     * 获取验证码
     */
    fun requestSendCode(tel: String) = launch {
        val jsonObject = JSONObject()
        jsonObject.put("tel",tel)
        jsonObject.put("userinfo",tel)
        jsonObject.put("type",6)

        viewModelRes.requestSendCode(tel,sendCodeBean)
    }

    /**
     * 验证 验证码
     */
    fun requestCheckSmsCode(tel: String,code: String) = launch {
        viewModelRes.requestCheckSmsCode(tel,code,checkSmsCodeBean)
    }

    /**
     * 登录
     */
    fun requestLogin(tel: String) = launch {
        viewModelRes.requestLogin(tel,loginBean)
    }

}